<template>
  <div>
    <el-form ref="formMatter" :model="formMatter" :inline="true">
      <el-form-item label="顾客名称">
        <el-select
            v-model="formMatter.customerName"
            filterable
            placeholder="请输入顾客名称"
            allow-create
            default-first-option
            clearable
            style="width: 10vw"
          >
            <el-option
              v-for="item in customerList"
              :key="item.id"
              :label="item.customerName"
              :value="item.customerName"
            >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="钢种">
        <el-select
          v-model="formMatter.steelGradeId"
          placeholder="请选择钢种"
          style="width: 10vw"
          filterable
          allow-create
          default-first-option
          clearable
        >
          <el-option
            v-for="item in steelGradeList"
            :key="item.id"
            :value="item.steelGradeName"
            :label="item.steelGradeName"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="钢类">
        <el-select
            v-model="formMatter.steelTypeId"
            placeholder="请选择钢类"
            style="width: 10vw"
            clearable
          >
          <el-option v-for="item in steelTypes" :key="item.id" :value="item.steelTypeName" :label="item.steelTypeName" />
        </el-select>
      </el-form-item>
      <el-form-item label="提交日期">
        <el-date-picker
          v-model="formMatter.submitTime"
          value-format="yyyy-MM-dd"
          style="width: 9vw"
          type="date"
          placeholder="选择日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="评审日期">
        <el-date-picker
          v-model="formMatter.reviewTime"
          value-format="yyyy-MM-dd"
          style="width: 9vw"
          type="date"
          placeholder="选择日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="编号">
        <el-input
          v-model="formMatter.code"
          style="width: 9vw"
          size="mini"
          placeholder="请输入"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item
        ><el-button type="primary" size="mini" @click="handleClick"
          >查询</el-button
        >
        <el-button type="success" size="mini" @click="handleReset"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <div>
      <el-card style="height: 100%">
        <div slot="header">已评审订单</div>
        <hmi-table
          :loading="tloading"
          :table-data="tableData"
          :current-page="currentPage"
          :page-size="pageSize"
          :total="total"
          :is-pagination-show="true"
          :table-height="'calc(100vh - 230px)'"
          index-tyle="index"
          @handle-size-change="handleSizeChange"
          @handle-current-change="handleCurrentChange"
        >
          <template slot="TableBody">
            <el-table-column
              label="序号"
              type="index"
              width="70"
              align="center"
            ></el-table-column>
            <el-table-column
              label="编号"
              align="center"
              prop="code"
            ></el-table-column>
            <el-table-column
              label="顾客名称"
              align="center"
              prop="customerName"
              width="200"
            ></el-table-column>
            <el-table-column
              label="顾客联系方式"
              align="center"
              width="160"
              prop="customerPhone"
            ></el-table-column>
            <el-table-column label="钢类" align="center" prop="steelTypeName"></el-table-column>
            <el-table-column label="钢种" align="center" prop="steelGradeName" show-overflow-tooltip></el-table-column>
            <el-table-column
              label="标准"
              align="center"
              prop="standardName"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              label="规格"
              align="center"
              prop="specification"
            ></el-table-column>
            <el-table-column
              label="数量"
              align="center"
              prop="steelNumber"
            ></el-table-column>
            <el-table-column
              label="交货状态"
              align="center"
              prop="deliveryStatus"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              label="加工用途"
              align="center"
              prop="processingPurpose"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column label="提交时间" align="center" prop="submitTime" show-overflow-tooltip>
              <template slot-scope="scope">
                <span>{{ formatterTime(scope.row.submitTime) }}</span>
              </template>
            </el-table-column>
            <el-table-column label="评审时间" align="center" prop="reviewTime" show-overflow-tooltip>
              <template slot-scope="scope">
                <span>{{ formatterTime(scope.row.reviewTime) }}</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="mini"
                  @click="hanldeDetail(scope.row)"
                  >查看</el-button
                >
              </template>
            </el-table-column>
          </template>
        </hmi-table>
      </el-card>
    </div>
  </div>
</template>

<script>
import { timeChange } from "@/lib/FormatTime";
import HmiTable from "../../../components/HmiTable.vue";
import { post } from "@/lib/Util.js";
import {
  getReviewedList,
  GET_STEELGRADELIST,
  GET_STEELTYPELIST,
  GET_CUSTOMERNAMELIST
} from "@/lib/Api.js";
export default {
  components: { HmiTable },
  data() {
    return {
      tloading: false,
      pageSize: 20,
      total: 0,
      currentPage: 1,
      formMatter: {},
      statuses: [],
      tableData: [],
      steelGradeList: [],
      steelTypes: [],
      customerList: []
    };
  },
  mounted() {
    this.getSteelGradeName();
    this.getsteelTypeNames();
    this.getCustomerNames();
    this.getData(this.currentPage, this.pageSize);
  },
  methods: {
    /**
     * 格式化日期方法
     */
    formatterTime(time) {
      if (time !== "" && time !== undefined) {
        return timeChange(time);
      } else {
        return "";
      }
    },
    hanldeDetail(row) {
      this.$router.push({
        name: "standard-approvedOrder-infoCompliance",
        params: {
          id: row.id
        }
      });
    },
    handleReset() {
      this.$refs.formMatter.resetFields();
    },
    handleClick() {
      this.getData(this.currentPage, this.pageSize);
    },
    //获取表格信息
    getData(page, num) {
      this.tloading = true;
      let data = Object.assign(this.formMatter, {
        current: page,
        page: num
      });
      post(getReviewedList, data).then(res => {
        if (res.code == 200) {
          this.tableData = res.rows;
          this.total = res.total;
        }
      });
      this.tloading = false;
    },
    //显示条数改变
    handleSizeChange(num) {
      this.pageSize = num;
      this.getData(1, num);
    },
    // 页数改变
    handleCurrentChange(page) {
      this.currentPage = page;
      this.getData(page, this.pageSize);
    },
    // 获取顾客
    getCustomerNames() {
      post(GET_CUSTOMERNAMELIST, { customerName: "" }).then(resp => {
        this.customerList = resp.data;
      });
    },
    // 获取钢类
    getsteelTypeNames() {
      post(GET_STEELTYPELIST, { steelTypeName: "" }).then(resp => {
        this.steelTypes = resp.data;
      });
    },
    getSteelGradeName() {
      post(GET_STEELGRADELIST, { steelGradeName: "" }).then(resp => {
        this.steelGradeList = resp.data;
      });
    }
  }
};
</script>

<style scoped>
</style>
